home *** CD-ROM | disk | FTP | other *** search
/ The Big Day - Work Smarter - Learn How / The Big Day - Work Smarter - Learn How (Microsoft).BIN / Certification / Microsoft Office User Specialist (MOUS) Certify Your Productivit / toolbar.js < prev   
Text File  |  2000-05-23  |  19KB  |  621 lines

  1.  
  2.  
  3. var ToolBar_Supported = false;
  4. var Frame_Supported   = false;
  5. var DoInstrumentation = false;
  6.  
  7. if (navigator.userAgent.indexOf("MSIE")    != -1 && 
  8.     navigator.userAgent.indexOf("Windows") != -1 && 
  9.     navigator.appVersion.substring(0,1) > 3)
  10. {
  11.     ToolBar_Supported = true;
  12. }
  13.  
  14. if (ToolBar_Supported)
  15. {
  16.     var newLineChar = String.fromCharCode(10);
  17.     var char34 = String.fromCharCode(34);
  18.     var LastMSMenu = "";
  19.     var CurICPMenu = "";
  20.     var IsMSMenu = false;
  21.     var IsMenuDropDown = true;
  22.     var HTMLStr;
  23.     var x = 0;
  24.     var y = 0;
  25.     var x2 = 0;
  26.     var y2 = 0;
  27.     var MSMenuWidth;
  28.     var ToolbarMinWidth;
  29.     var ToolbarMenu;
  30.     var ToolbarBGColor;
  31.     var ToolbarLoaded = false;
  32.     var aDefMSColor  = new Array(3);
  33.     var aDefICPColor = new Array(3);
  34.     var aCurMSColor  = new Array(3);
  35.     var aCurICPColor = new Array(3);
  36.     var MSFont;
  37.     var ICPFont;
  38.     var MaxMenu = 30;
  39.     var TotalMenu = 0;
  40.     var arrMenuInfo = new Array(30);
  41.  
  42.     // Output style sheet and toolbar ID
  43.     document.write("<SPAN ID='StartMenu' STYLE='display:none;'></SPAN>");
  44.  
  45.     // Build toolbar template
  46.     HTMLStr = 
  47.         "<DIV ID='idToolbar'     STYLE='background-color:white;width:100%'>" +
  48.         "<DIV ID='idRow1'        STYLE='position:relative;height:20;'>" +
  49.         "<DIV ID='idICPBanner'   STYLE='position:absolute;top:0;left:0;height:60;width:250;overflow:hidden;vertical-align:top;'><!--BEG_ICP_BANNER--><!--END_ICP_BANNER--></DIV>" +
  50.         "<DIV ID='idMSMenuCurve' STYLE='position:absolute;top:0;left:250;height:20;width:18;overflow:hidden;vertical-align:top;'><IMG SRC='/images/banner_round.gif' BORDER=0></DIV>" +
  51.         "<DIV ID='idMSMenuPane'  STYLE='position:absolute;top:0;left:250;height:20;width:10;background-color:black;float:right;' NOWRAP><!--MS_MENU_TITLES--></DIV>" + 
  52.         "</DIV>" +
  53.         "<DIV ID='idRow2' STYLE='position:relative;left:250;height:40;'>" +
  54.         "<DIV ID='idADSBanner'   STYLE='position:absolute;top:0;left:0;height:40;width:200;vertical-align:top;overflow:hidden;'><!--BEG_ADS_BANNER--><!--END_ADS_BANNER--></DIV>" +
  55.         "<DIV ID='idMSCBanner'   STYLE='position:absolute;top:0;left:200;height:40;width:112;vertical-align:top;overflow:hidden;' ALIGN=RIGHT><!--BEG_MSC_BANNER--><!--END_MSC_BANNER--></DIV>" +
  56.         "</DIV>" +
  57.         "<DIV ID='idRow3' STYLE='position:relative;height:20;width:100%'>" +
  58.         "<DIV ID='idICPMenuPane' STYLE='position:absolute;top:0;left:0;height:20;background-color:black;' NOWRAP><!--ICP_MENU_TITLES--></DIV>" +
  59.         "</DIV>" +
  60.         "</DIV>" +
  61.         "<SCRIPT TYPE='text/javascript'>" + 
  62.         "   var ToolbarMenu = StartMenu;" + 
  63.         "</SCRIPT>" + 
  64.         "<DIV WIDTH=100%>";
  65.  
  66.     // Define event handlers
  67.     window.onresize  = resizeToolbar;
  68.  
  69.     // Intialize global variables
  70.     ToolbarBGColor    = "#000000";                        // toolbar background color
  71.     MSFont  = "xx-small Verdana";
  72.     ICPFont = "bold xx-small Verdana";
  73.     
  74.     aDefMSColor[0]    = aCurMSColor[0]  = "black";    // bgcolor;
  75.     aDefMSColor[1]    = aCurMSColor[1]  = "white";    // text font color
  76.     aDefMSColor[2]  = aCurMSColor[2]  = "red";        // mouseover font color
  77.     
  78.     aDefICPColor[0]    = aCurICPColor[0] = "#6699CC";    // bgcolor;
  79.     aDefICPColor[1] = aCurICPColor[1] = "white";    // text font color
  80.     aDefICPColor[2] = aCurICPColor[2] = "red";        // mouseover font color
  81. }
  82.  
  83. // The hard-coded numbers in functions - drawToolbar() & resizeToolbar()
  84. // correspond to the dimension of the four gif files:
  85. //        ICP_BANNER: 60h x 250w
  86. //        ADS_BANNER: 40h x 200w
  87. //        MSC_BANNER: 40h x 112w
  88. //        Curve:        20h x 18w
  89.  
  90. function drawToolbar()
  91. {
  92.     HTMLStr += "</DIV>";
  93.     document.write(HTMLStr);
  94.     ToolbarLoaded = true;
  95.  
  96.     MSMenuWidth     = Math.max(idMSMenuPane.offsetWidth, (200+112));
  97.     ToolbarMinWidth = (250+18) + MSMenuWidth;
  98.  
  99.     idToolbar.style.backgroundColor     = ToolbarBGColor;
  100.     idMSMenuPane.style.backgroundColor  = aDefMSColor[0];
  101.     idICPMenuPane.style.backgroundColor = aDefICPColor[0];
  102.     resizeToolbar();
  103.  
  104.     for (i = 0; i < TotalMenu; i++) 
  105.     {
  106.         thisMenu = document.all(arrMenuInfo[i].IDStr);
  107.         if (thisMenu != null)
  108.         {
  109.             if (arrMenuInfo[i].IDStr == LastMSMenu && arrMenuInfo[i].type == "R")
  110.             {
  111.                 //Last MSMenu has to be absolute width
  112.                 arrMenuInfo[i].type = "A";
  113.                 arrMenuInfo[i].unit = 200;
  114.             }
  115.             if (arrMenuInfo[i].type == "A")
  116.                 thisMenu.style.width = arrMenuInfo[i].unit;
  117.             else 
  118.                 thisMenu.style.width = Math.round(arrMenuInfo[i].width * arrMenuInfo[i].unit) + 'em';
  119.         }
  120.     }
  121. }
  122.  
  123. function resizeToolbar()
  124. {
  125.     if (ToolBar_Supported == false) return;
  126.  
  127.     w = Math.max(ToolbarMinWidth, document.body.clientWidth) - ToolbarMinWidth;
  128.     
  129.     idMSMenuCurve.style.left  = (250+w);
  130.     idMSMenuPane.style.left   = (250+w+18);
  131.     idMSMenuPane.style.width  = MSMenuWidth;
  132.  
  133.     idADSBanner.style.left    = (w+18);
  134.  
  135.     idMSCBanner.style.left    = (w+18+200);
  136.     idMSCBanner.style.width   = (MSMenuWidth - 200);
  137.     
  138.     idICPMenuPane.style.width = ToolbarMinWidth + w;
  139. }
  140.  
  141. function setToolbarBGColor(color)
  142. {    
  143.     ToolbarBGColor = color;
  144.     if (ToolbarLoaded == true)
  145.         idToolbar.style.backgroundColor = ToolbarBGColor;
  146. }    
  147.  
  148. function setMSMenuFont(sFont)
  149. {    MSFont = sFont;
  150. }
  151.  
  152. function setICPMenuFont(sFont)
  153. {    ICPFont = sFont;
  154. }
  155.  
  156. function setDefaultMSMenuColor(bgColor, fontColor, mouseoverColor)
  157. {    
  158.     if (bgColor   != "")      aDefMSColor[0] = bgColor;
  159.     if (fontColor != "")      aDefMSColor[1] = fontColor;
  160.     if (mouseoverColor != "") aDefMSColor[2] = mouseoverColor;
  161. }
  162.  
  163. function setDefaultICPMenuColor(bgColor, fontColor, mouseoverColor)
  164. {    
  165.     if (bgColor   != "")      aDefICPColor[0] = bgColor;
  166.     if (fontColor != "")      aDefICPColor[1] = fontColor;
  167.     if (mouseoverColor != "") aDefICPColor[2] = mouseoverColor;
  168. }
  169.  
  170. function setICPMenuColor(MenuIDStr, bgColor, fontColor, mouseoverColor)
  171. {    
  172.     if (ToolbarLoaded == false) return;
  173.  
  174.     // Reset previous ICP Menu color if any
  175.     if (CurICPMenu != "")
  176.     {
  177.         PrevID = CurICPMenu.substring(4);
  178.         CurICPMenu = "";
  179.         setICPMenuColor(PrevID, aDefICPColor[0], aDefICPColor[1], aDefICPColor[2]);
  180.     }
  181.  
  182.     var    id = "AM_" + "ICP_" + MenuIDStr;
  183.     var thisMenu = document.all(id);
  184.     if (thisMenu != null)
  185.     {
  186.         CurICPMenu = "ICP_" + MenuIDStr;
  187.         aCurICPColor[0] = bgColor;
  188.         aCurICPColor[1] = fontColor;
  189.         aCurICPColor[2] = mouseoverColor;
  190.  
  191.         // Change menu color
  192.         if (bgColor != "")
  193.             thisMenu.style.backgroundColor = bgColor;
  194.         if (fontColor != "")
  195.             thisMenu.style.color = fontColor;
  196.  
  197.         // Change subMenu color
  198.         id = "ICP_" + MenuIDStr;
  199.         thisMenu = document.all(id);
  200.         if (thisMenu != null)
  201.         {
  202.             if (bgColor != "")
  203.                 thisMenu.style.backgroundColor = bgColor;
  204.             
  205.             if (fontColor != "")
  206.             {
  207.                 i = 0;
  208.                 id = "AS_" + "ICP_" + MenuIDStr;
  209.                 thisMenu = document.all.item(id,i);
  210.                 while (thisMenu != null)
  211.                 {
  212.                     thisMenu.style.color = fontColor;
  213.                     i += 1;
  214.                     thisMenu = document.all.item(id,i);
  215.                 }
  216.             }
  217.         }
  218.     }
  219. }
  220.  
  221. function setAds(Gif,Url,AltStr)
  222. {    setBanner(Gif,Url,AltStr,"<!--BEG_ADS_BANNER-->","<!--END_ADS_BANNER-->");
  223. }
  224.  
  225. function setICPBanner(Gif,Url,AltStr)
  226. {    setBanner(Gif,Url,AltStr,"<!--BEG_ICP_BANNER-->","<!--END_ICP_BANNER-->");
  227. }
  228.  
  229. function setMSBanner(Gif,Url,AltStr)
  230. {    tempGif = "/images/" + Gif;
  231.     setBanner(tempGif,Url,AltStr,"<!--BEG_MSC_BANNER-->","<!--END_MSC_BANNER-->");
  232. }
  233.  
  234. function setBanner(BanGif, BanUrl, BanAltStr, BanBegTag, BanEndTag)
  235. {
  236.     begPos = HTMLStr.indexOf(BanBegTag);
  237.     endPos = HTMLStr.indexOf(BanEndTag) + BanEndTag.length;
  238.     
  239.     SubStr = HTMLStr.substring(begPos, endPos);
  240.     SrcStr = "";
  241.     if (BanUrl != "")
  242.         SrcStr += "<A Target='_top' HREF='" + formatURL(BanUrl, BanGif) + "'>";
  243.     SrcStr += "<IMG SRC='" + BanGif + "' ALT='" + BanAltStr + "' BORDER=0>";
  244.     if (BanUrl != "")
  245.         SrcStr += "</A>";
  246.     SrcStr = BanBegTag + SrcStr + BanEndTag;
  247.     HTMLStr = HTMLStr.replace(SubStr, SrcStr);    
  248. }
  249.  
  250. function setICPSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  251. {    tempID = "ICP_" + MenuIDStr;
  252.     setSubMenuWidth(tempID, WidthType, WidthUnit);
  253. }
  254.  
  255. function setMSSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  256. {    tempID = "MS_" + MenuIDStr;
  257.     setSubMenuWidth(tempID, WidthType, WidthUnit);
  258. }
  259.  
  260. function setSubMenuWidth(MenuIDStr, WidthType, WidthUnit)
  261. {
  262.     var fFound = false;
  263.     if (TotalMenu == MaxMenu)
  264.     {
  265.         alert("Unable to process menu. Maximum of " + MaxMenu + " reached.");
  266.